<template>
  <div>
    <el-card shadow="always" :body-style="{ padding: '20px' }">
      <CategorySelector :disabled="showState !== 1"></CategorySelector>
    </el-card>
    <el-card
      shadow="always"
      :body-style="{ padding: '20px' }"
      style="margin-top: 20px"
    >
      <SpuList v-if="showState === 1" @changeState="changeState"></SpuList>
      <SpuForm
        v-else-if="showState === 2"
        :spu="spu"
        @changeState="changeState"
      ></SpuForm>
      <SkuForm v-else :spu="spu" @changeState="changeState"></SkuForm>
    </el-card>
  </div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
  name: "Spu",
});
</script>
<script lang="ts" setup>
import SkuForm from "./components/SkuForm/index.vue";
import SpuForm from "./components/SpuForm/index.vue";
import SpuList from "./components/SpuList/index.vue";
import type { SpuData } from "@/api/spu";
import { ref } from "vue";
const showState = ref(1);

const spu = ref<SpuData>({
  spuName: "",
  description: "",
  category3Id: "",
  tmId: "",
  spuSaleAttrList: [],
  spuImageList: [],
});

// 定义添加修改自定义事件回调
const changeState = (num: number, row: SpuData) => {
  showState.value = num;
  if (row) {
    // 修改
    spu.value = row;
  } else {
    spu.value = {
      spuName: "",
      description: "",
      category3Id: "",
      tmId: "",
      spuSaleAttrList: [],
      spuImageList: [],
    };
  }
};
</script>

<style lang="less" scoped></style>
